package com.namo.cchapi.config;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import com.namo.cchapi.util.Bmob;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WangXin
 * @date 2021/4/12 10:49
 */
@Configuration
@RefreshScope
public class CaptchaConfig {

    @Value("${bmob.message.appid}")
    private String appID;
    @Value("${bmob.message.appkey}")
    private String appKey;
    @Value("${bmob.message.template}")
    private String template;

    @Bean
    public LineCaptcha lineCaptcha(){
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 45, 4, 4);
        // 自定义验证码内容为四则运算方式
//        lineCaptcha.setGenerator(new MathGenerator(1));
        return lineCaptcha;
    }

    @Bean
    public Bmob bmob(){
        Bmob bmob = new Bmob(appID,appKey,template);
        return bmob;
    }
}
